﻿using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Text;

namespace HigLabo.Net.BoxNet
{
    /// <summary>
    /// 
    /// </summary>
    public class UpdateFileInfoCommand : BoxCommand
    {
        /// <summary>
        /// 
        /// </summary>
        public String FileID { get; set; }
        /// <summary>
        /// 
        /// </summary>
        public String Name { get; set; }
        /// <summary>
        /// 
        /// </summary>
        public String Description { get; set; }
        /// <summary>
        /// 
        /// </summary>
        public AccessType? Access { get; set; }
        /// <summary>
        /// 
        /// </summary>
        public Boolean CanDownload { get; set; }
        /// <summary>
        /// 
        /// </summary>
        public Boolean CanPreview { get; set; }
        /// <summary>
        /// 
        /// </summary>
        public override HttpMethodName MethodName
        {
            get
            {
                return HttpMethodName.Put;
            }
        }

        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        protected override string CreateMethodPath()
        {
            return String.Format("/files/{0}", FileID);
        }
        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        protected override byte[] SetData()
        {
            var d = new Dictionary<String, Object>();

            d["name"] = this.Name;
            d["description"] = this.Description;
            if (this.Access.HasValue == true)
            {
                d["shared_link"] = new
                {
                    access = this.Access.ToString().ToLower(),
                    permissions = new
                    {
                        download = this.CanDownload,
                        preview = this.CanPreview
                    }
                };
            }
            var text = JsonConvert.SerializeObject(d);
            return Encoding.UTF8.GetBytes(text);
        }
    }
}
